package com.oasistudio.ads.expert.other;

import com.adwo.adsdk.AdwoSplashAdActivity;
import com.adwo.adsdk.ErrorCode;
import com.adwo.adsdk.FSAd;
import com.adwo.adsdk.FSAdUtil;
import com.adwo.adsdk.SplashAdListener;
import com.oasistudio.ads.expert.banner.AdViewAdwo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class AdwoFullScreen extends Activity implements SplashAdListener{

	FSAdUtil adUtil;
	private static final int SPLASH_AD_REQUEST = 10;
	//private static final int AD_SKIP = 998;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		FSAdUtil adUtil = FSAdUtil.getInstance(); // 得到FSAdUtil对象
		System.out.println("OtherAdwo.onCreate() adUtil = "+adUtil);
		// 设置监听
		adUtil.setSplashAdListener(this);
		System.out.println("OtherAdwo.onCreate() adUtil 2 = "+adUtil);
		// 向服务器请求广告
		adUtil.loadAd(this, // Activity 或 Context
				AdViewAdwo.Adwo_PID, // Adwo_PID
				true); // 请求的广告是否是竖屏 竖屏为 true 横屏为 false
		System.out.println("OtherAdwo.onCreate() adUtil 3 = "+adUtil);
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		System.out.println("OtherAdwo.onActivityResult() requestCode = " + requestCode + " resultCode=" + resultCode + " data=" + data);
		switch (requestCode) {
		case SPLASH_AD_REQUEST:
			// 用户跳过了全屏广告
			// if (resultCode == AdwoSplashAdActivity..AD_SKIP) {
			// Intent mIntent = new Intent(this, NextActivity.class);
			// startActivity(mIntent);
			// finish(); // 把当前Activity finish销毁掉
			// }
		}
	}

	@Override
	public void onReceiveAd(FSAd fsAd) {
		System.out.println("OtherAdwo.onReceiveAd() fsAd.describeContents() = " + fsAd.describeContents());
		if (fsAd != null) {
			System.out.println("OtherAdwo.onReceiveAd() fsAd != null 1");
			Intent splashAdsIntent = new Intent(this, AdwoSplashAdActivity.class);
			System.out.println("OtherAdwo.onReceiveAd() fsAd != null 2");
			splashAdsIntent.putExtra("FSAd", fsAd);
			System.out.println("OtherAdwo.onReceiveAd() fsAd != null 3");
			// 把广告对象传给全屏广告页面
			startActivityForResult(splashAdsIntent, SPLASH_AD_REQUEST);
			System.out.println("OtherAdwo.onReceiveAd() fsAd != null 4");
		}
	}

	@Override
	public void onFailedToReceiveAd(ErrorCode errorCode) {
		System.out.println("OtherAdwo.onReceiveAd() ErrorCode = " + errorCode);
		System.out.println("OtherAdwo.onReceiveAd() ErrorCode.code = " + errorCode.getErrorCode());
		System.out.println("OtherAdwo.onReceiveAd() ErrorCode.string = " + errorCode.getErrorString());
		// TODO Auto-generated method stub
		
	}
}
